/**
 * Created by Administrator on 2016/11/3.
 * 首页控制层
 */

const logger   = require('../../common/logger').logger;
const _interface = require('../models/interface/interface');
var ModelProxy = require('../../modelproxy/modelproxy');
exports.index = function(req, res) {
  _interface.qeuryModules()
  .withCookie( req.headers.cookie )
  .done(function(data, setCookie, orginRet) {
    if (orginRet.headers.islogin !== '0') {
      data = JSON.parse(data).data || [];
      res.render('index', {
        username: req.session.userInfo.userName,
        title: '组件管理',
        current: 'index',
        modulesList: data
      });
    } else {
      res.redirect('/login')
    }
  })
  .error((err) => {
    logger.info(err)
  })
}
exports.zhgl = function(req, res) {
  res.render('zhgl', {
    username: req.session.userInfo.userName,
    title: '账号管理',
    current: 'index',
    dataSet: {}
  });
}
exports.ywxt = function(req, res) {
   _interface.ssoServiceSystemList({
   })
   .done((data, setCookie, orginRet) => {
     console.log(orginRet.headers)
    if (orginRet.headers.islogin === '0') {
      res.redirect('/login')
    } else {data = JSON.parse(data);
      if (data.code === '0') {
         res.render('ywxt', {
            username: req.session.userInfo.userName,
           title: '业务系统',
           current: 'index',
           systemList: data.data
         });
       }
    }
   })
}
exports.login = function(req, res) {
  res.render('login');
}
